using System;

namespace Meta.Editor
{
	/// <summary>
	/// Wraps a CodeScanner as a System.IO.TextReader for use by Reader.
	/// </summary>
	public class EditorTextReader : System.IO.TextReader
	{
		public CodeScanner scanner;

		public EditorTextReader(CodeScanner scanner) {
			this.scanner = scanner;
		}

		public EditorTextReader(CodeBox code, int position) {
			scanner = code.ScanCharsFrom(position);
		}

		public override int Peek() {
			if (scanner.AtEndOfBuffer)
				return -1;
			else
				return scanner.CurrentChar;
		}

		public override int Read() {
			if (scanner.AtEndOfBuffer)
				return -1;
			else
				return scanner.Forward();
		}
	}
}
